package com.sqxgg.drugstore.email.service;

import com.sqxgg.drugstore.email.entity.EmailEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;

@Service
    public class SendEmailService  {
    @Autowired
    JavaMailSenderImpl javaMailSender;
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    public String sendEmail(EmailEntity emailEntity){
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject(emailEntity.getSubject());
        simpleMailMessage.setText(emailEntity.getEmailTest());
        simpleMailMessage.setFrom("MyDreamChangeWorld@163.com");
        simpleMailMessage.setTo(emailEntity.getTo());
        simpleMailMessage.setCc(emailEntity.getCc());
        try {
            logger.info("开始发送了");
            javaMailSender.send(simpleMailMessage);
            logger.info("结束发送");
        }catch (Exception e){
            logger.info("发送报错：==="+e.getMessage());
            return "ERROR:"+e.getMessage();
        }
       return "SUCCESS";
    }
}
